const path = require('path')
const port = 3000
const isDev = process.env.NODE_ENV === 'development'

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: '/', // 添加URL前缀
  outputDir: 'dist',
  assetsDir: 'assets',
  filenameHashing: true,
  lintOnSave: false, // 保存时，是否使用eslint
  runtimeCompiler: false,
  transpileDependencies: [],
  productionSourceMap: false,
  devServer: {
    open: true,
    port,
    overlay: {
      warnings: false,
      errors: true
    },
    https: false,
    hotOnly: false,
    disableHostCheck: true
  },
  chainWebpack: (config) => {
    config
      .plugin('html')
      .tap((args) => {
        args[0].title = '表单动态设计'
        return args
      })

    config.module
      .rule('eslint')
      .exclude.add(resolve('src/libs'))
      .end()

    config
      .when(isDev,
        config => config.devtool('cheap-source-map')
      )
  },
  css: {
    requireModuleExtension: true,
    extract: true,
    sourceMap: false,
    loaderOptions: {
      less: {
        modifyVars: {
          'font-size-base': '13px',
          'tabs-title-font-size': '14px'
        },
        javascriptEnabled: true
      }
    }
  },
  parallel: require('os').cpus().length > 1
}
